--荷戟彷徨
local hejifanghuang = fk.CreateSkill {
    name = "mcdh_hejifanghuang",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

hejifanghuang:addEffect('viewas',{
    card_filter = Util.FalseFunc,
    pattern = "nullification,jink",
    enabled_at_play = function(self, player)
        if  lib.mcdh_getLoseammo(player) == 0 then
            return false
        end
        local card
        if player.chained then
            card = Fk:cloneCard("jink")
        else
            card = Fk:cloneCard("nullification")
        end
        return ((Fk.currentResponsePattern == nil and player:canUse(card)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)))
    end,
    enabled_at_response  = function(self, player, response)
        if lib.mcdh_getLoseammo(player) == 0 or response then
            return false
        end
        local card
        if player.chained then
            card = Fk:cloneCard("jink")
        else
            card = Fk:cloneCard("nullification")
        end
        return ((Fk.currentResponsePattern == nil and player:canUse(card)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)))
    end,
    view_as = function(self, player,cards)
        local card
        if player:hasSkill(self) then
            if player.chained then
                card = Fk:cloneCard("jink")
            else
                card = Fk:cloneCard("nullification")
            end
        end
        card.skillName = self.name
        return card
    end,
    before_use = function(self, player, use)
        lib.LoadAmmo(player,player,1,self.name)
        if player.chained then
            player:setChainState(false)
        else
            player:setChainState(true)
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_hejifanghuang"] = "彷徨",
    [":mcdh_hejifanghuang"] = "『荷戟彷徨』<br>你可以装填1枚弹药并：横置武将牌并视为使用一张【无懈可击】；重置武将牌并视为使用一张【闪】。",
}

return hejifanghuang